package com.cdn.allmobilestore.loader;

import java.util.ArrayList;

import org.json.JSONObject;

import android.content.Context;

import com.cdn.allmobilestore.model.AppInfo;
import com.cdn.allmobilestore.model.ListAppInfo;
import com.cdn.allmobilestore.ulti.Constant;
import com.cdn.allmobilestore.ulti.Request;

public class HomeLoader extends BaseLoader
{
    public HomeLoader(Context paramContext)
    {
        super(paramContext);
    }
    
   
    protected BaseResult getResultInstance()
    {
        return new Result();
    }
    
    protected BaseLoader.UpdateTask getUpdateTask()
    {
        return new HomeUpdateTask();
    	
    }
    
    protected BaseResult parseResult(JSONObject json, BaseResult result)
    throws Exception
    {
        Result localResult = (Result)result;
        localResult.mHomeInfos = ListAppInfo.valueOfAray(json);
        return localResult;
    }
    
    private class HomeUpdateTask extends BaseLoader.UpdateTask
    {
        private HomeUpdateTask()
        {
            super();
        }

		@Override
		protected Request getRequest() {
			// TODO Auto-generated method stub
			return new Request(String.format(Constant.GET_LISTAPP_URL, "home",""));
		}
             
    }
    
    public static final class Result extends BaseResult
    {
        public ArrayList<AppInfo> mHomeInfos;
        
        protected int getCount()
        {
        	int count = 0;
            if (this.mHomeInfos != null)
             count = this.mHomeInfos.size();
            return count;
        }
        
        public BaseResult shallowClone()
        {
            Result localResult = new Result();
            localResult.mHomeInfos = this.mHomeInfos;
            return localResult;
        }
    }

	
}